<internal>
Index
Classes
Type Aliases
Classes
default
constructor
Initializes Plugins.
Parameters
options: { loadDefaultPlugins: boolean } = ...
module options including user plugins to load including:
(boolean) loadDefaultPlugins - When false ESComplexModule will not load any default plugins.
(Array<Object>) plugins - A list of ESComplexModule plugins that have already been instantiated.
Returns default
onConfigure
Initializes the default
settings
object hash and then invokes theonConfigure
plugin callback for all loaded plugins.Parameters
options: ComplexityReporterOptions
(Optional) module processing options.
Returns any
onEnterNode
Invokes the
onEnterNode
plugin callback during AST traversal when a node is entered.Parameters
moduleReport: default
The ModuleReport being processed.
scopeControl: any
The associated module report scope control.
ignoreKeys: string[]
Any syntax assigned ignore keys for AST traversal.
syntaxes: any
All loaded trait syntaxes for AST nodes.
settings: any
Settings for module processing.
node: any
The node being entered.
parent: any
The parent node of the node being entered.
Returns string[]
A directive indicating children keys to be skipped or if null all keys entirely.
onExitNode
Invokes the
onExitNode
plugin callback during AST traversal when a node is exited.Parameters
moduleReport: default
The ModuleReport being processed.
scopeControl: any
The associated module report scope control.
syntaxes: any
All loaded trait syntaxes for AST nodes.
settings: any
Settings for module processing.
node: any
The node being entered.
parent: any
The parent node of the node being entered.
Returns void
onLoadSyntax
Initializes the trait
syntaxes
object hash and then invokes theonLoadSyntax
plugin callback for all loaded plugins.Parameters
settings: any
Settings for module processing.
Returns any
Loaded trait
syntaxes
for AST nodes.
onModuleAverage
Invokes the
onModuleAverage
plugin callback for all loaded plugins such they might average any calculated results.Parameters
moduleReport: default
The ModuleReport being processed.
syntaxes: any
All loaded trait syntaxes for AST nodes.
settings: any
Settings for module processing.
Returns default
The ModuleReport being processed.
onModuleCalculate
Invokes the
onModuleCalculate
plugin callback for all loaded plugins such they might finish calculating results.Parameters
moduleReport: default
The ModuleReport being processed.
syntaxes: any
All loaded trait syntaxes for AST nodes.
settings: any
Settings for module processing.
Returns default
The ModuleReport being processed.
onModuleEnd
Invokes the
onModuleEnd
plugin callback for all loaded plugins at the end of module processing.Parameters
moduleReport: default
The ModuleReport being processed.
syntaxes: any
All loaded trait syntaxes for AST nodes.
settings: any
Settings for module processing.
Returns default
The ModuleReport being processed.
onModulePostAverage
Invokes the
onModulePostAverage
plugin callback for all loaded plugins such they might finish any calculations that involve averaged results.Parameters
moduleReport: default
The ModuleReport being processed.
syntaxes: any
All loaded trait syntaxes for AST nodes.
settings: any
Settings for module processing.
Returns default
The ModuleReport being processed.
onModulePostScopeCreated
Invokes the
onModulePostScopeCreated
plugin callback during AST traversal after a new module report scope is created.Parameters
moduleReport: default
The ModuleReport being processed.
scopeControl: any
The associated module report scope control.
newScope: Scope
An object hash defining the new scope including:
settings: any
Settings for module processing.
node: any
The node being entered.
parent: any
The parent node of the node being entered.
Returns void
onModulePostScopePopped
Invokes the
onModulePostScopePopped
plugin callback during AST traversal after a module report scope is popped / exited.Parameters
moduleReport: default
The ModuleReport being processed.
scopeControl: any
The associated module report scope control.
scope: Scope
An object hash defining the new scope including:
settings: any
Settings for module processing.
node: any
The node being entered.
parent: any
The parent node of the node being entered.
Returns void
onModulePreScopeCreated
Invokes the
onModulePreScopeCreated
plugin callback during AST traversal before a new module report scope is created.Parameters
moduleReport: default
The ModuleReport being processed.
scopeControl: any
The associated module report scope control.
newScope: Scope
An object hash defining the new scope including:
settings: any
Settings for module processing.
node: any
The node being entered.
parent: any
The parent node of the node being entered.
Returns void
onModulePreScopePopped
Invokes the
onModulePreScopePopped
plugin callback during AST traversal before a module report scope is popped / exited.Parameters
moduleReport: default
The ModuleReport being processed.
scopeControl: any
The associated module report scope control.
scope: Scope
An object hash defining the new scope including:
settings: any
Settings for module processing.
node: any
The node being entered.
parent: any
The parent node of the node being entered.
Returns void
onModuleStart
Initializes the default ModuleReport and then invokes the
onModuleStart
plugin callback for all loaded plugins.Parameters
ast: Node
Settings for module processing.
syntaxes: any
All loaded trait syntaxes for AST nodes.
settings: any
Settings for module processing.
Returns default
The ModuleReport being processed.
default
Provides a lightweight plugin manager for Node / NPM with optional backbone-esnext-events
integration for plugins in a safe and protected manner across NPM modules, local files, and preloaded object
instances. This pattern facilitates message passing between modules versus direct dependencies / method invocation.
It isn’t necessary to use an eventbus associated with the plugin manager though invocation then relies on invoking methods directly with the plugin manager instance.
When passing in an eventbus from backbone-esnext-events
the plugin manager will register by default under these
event categories:
plugins:add
- PluginManager#add
plugins:add:all
- PluginManager#addAll
plugins:async:add
- PluginManager#addAsync
plugins:async:add:all
- PluginManager#addAllAsync
plugins:async:destroy:manager
- PluginManager#destroyAsync
plugins:async:invoke
- PluginManager#invokeAsync
plugins:async:invoke:event
- PluginManager#invokeAsyncEvent
plugins:async:remove
- PluginManager#removeAsync
plugins:async:remove:all
- PluginManager#removeAllAsync
plugins:create:event:proxy
- PluginManager#createEventProxy
plugins:destroy:manager
- PluginManager#destroy
plugins:get:all:plugin:data
- PluginManager#getAllPluginData
plugins:get:extra:event:data
- PluginManager#getExtraEventData
plugins:get:method:names
- PluginManager#getMethodNames
plugins:get:options
- PluginManager#getOptions
plugins:get:plugin:data
- PluginManager#getPluginData
plugins:get:plugin:enabled
- PluginManager#getPluginEnabled
plugins:get:plugin:event:names
- PluginManager#getPluginEventNames
plugins:get:plugin:method:names
- PluginManager#getPluginMethodNames
plugins:get:plugin:names
- PluginManager#getPluginNames
plugins:get:plugin:options
- PluginManager#getPluginOptions
plugins:get:plugins:enabled
- PluginManager#getPluginsEnabled
plugins:get:plugins:by:event:name
- PluginManager#getPluginsByEventName
plugins:get:plugins:event:names
- PluginManager#getPluginsEventNames
plugins:has:method
- PluginManager#hasMethod
plugins:has:plugin
- PluginManager#hasPlugin
plugins:has:plugin:method
- PluginManager#hasPluginMethod
plugins:invoke
- PluginManager#invoke
plugins:is:valid:config
- PluginManager#isValidConfig
plugins:remove
- PluginManager#remove
plugins:remove:all
- PluginManager#removeAll
plugins:set:extra:event:data
- PluginManager#setExtraEventData
plugins:set:options
- PluginManager#setOptions
plugins:set:plugin:enabled
- PluginManager#setPluginEnabled
plugins:set:plugins:enabled
- PluginManager#setPluginsEnabled
plugins:sync:invoke
- PluginManager#invokeSync
plugins:sync:invoke:event
- PluginManager#invokeSyncEvent
Automatically when a plugin is loaded and unloaded respective callbacks onPluginLoad
and onPluginUnload
will
be attempted to be invoked on the plugin. This is an opportunity for the plugin to receive any associated eventbus
and wire itself into it. It should be noted that a protected proxy around the eventbus is passed to the plugins
such that when the plugin is removed automatically all events registered on the eventbus are cleaned up without
a plugin author needing to do this manually in the onPluginUnload
callback. This solves any dangling event binding
issues.
The plugin manager also supports asynchronous operation with the methods ending in Async
along with event bindings
that include async
. For asynchronous variations of add
, destroy
, and remove
the lifecycle methods
onPluginLoad
and onPluginUnload
will be awaited on such that if a plugin returns a Promise or is an async method
then it must complete before execution continues. One can use Promises to interact with the plugin manager
asynchronously, but usage via async / await is recommended.
If eventbus functionality is enabled it is important especially if using a process / global level eventbus such as
backbone-esnext-eventbus
to call PluginManager#destroy to clean up all plugin eventbus resources and
the plugin manager event bindings.
constructor
Instantiates PluginManager
Parameters
optionaloptions: { eventPrepend?: string; eventbus?: EventEmitter; throwNoMethod: boolean; throwNoPlugin: boolean }
Provides various configuration options:
options.eventbus - An instance of ‘backbone-esnext-events’ used as the plugin eventbus.
options.eventPrepend - A customized name to prepend PluginManager events on the eventbus.
options.throwNoMethod - If true then when a method fails to be invoked by any plugin an exception will be thrown.
options.throwNoPlugin- If true then when no plugin is matched to be invoked an exception will be thrown.
optionalextraEventData: string
Provides additional optional data to attach to PluginEvent callbacks.
Returns default
add
Adds a plugin by the given configuration parameters. A plugin
name
is always required. If no other options are provided then thename
doubles as the NPM module / local file to load. The loading first checks for an existinginstance
to use as the plugin. Then thetarget
is chosen as the NPM module / local file to load. By passing inoptions
this will be stored and accessible to the plugin during all callbacks.Parameters
pluginConfig: PluginConfig
Defines the plugin to load.
optionalmoduleData: any
Optional object hash to associate with plugin.
Returns PluginData
addAll
Initializes multiple plugins in a single call.
Parameters
optionalpluginConfigs: PluginConfig[]
An array of plugin config object hash entries.
optionalmoduleData: any
Optional object hash to associate with all plugins.
Returns PluginData[]
addAllAsync
Initializes multiple plugins in a single call.
Parameters
optionalpluginConfigs: PluginConfig[]
An array of plugin config object hash entries.
optionalmoduleData: any
Optional object hash to associate with all plugins.
Returns Promise<PluginData[]>
addAsync
Adds a plugin by the given configuration parameters. A plugin
name
is always required. If no other options are provided then thename
doubles as the NPM module / local file to load. The loading first checks for an existinginstance
to use as the plugin. Then thetarget
is chosen as the NPM module / local file to load. By passing inoptions
this will be stored and accessible to the plugin during all callbacks.Parameters
pluginConfig: PluginConfig
Defines the plugin to load.
optionalmoduleData: any
Optional object hash to associate with plugin.
Returns Promise<PluginData>
createEventProxy
If an eventbus is assigned to this plugin manager then a new EventEmitter wrapping this eventbus is returned.
Returns EventEmitter
destroy
Destroys all managed plugins after unloading them.
Returns void
destroyAsync
Destroys all managed plugins after unloading them.
Returns Promise<void>
getAllPluginData
Returns all plugin data or if a boolean is passed in will return plugin data by current enabled state.
Parameters
enabled: boolean
If enabled is a boolean it will return plugins given their enabled state.
Returns PluginData[]
getEventbus
Returns any associated eventbus.
Returns EventEmitter
getExtraEventData
Returns any extra event data associated with PluginEvents.
Returns any
getMethodNames
Returns all method names or if a boolean is passed in will return method names for plugins by current enabled state.
Parameters
enabled: boolean
If enabled is a boolean it will return plugin methods names given their enabled state.
pluginName: string
If a string then just this plugins methods names are returned.
Returns string[]
getOptions
Returns a copy of the plugin manager options.
Returns PluginManagerOptions
getPluginData
Gets the plugin data for a plugin by name.
Parameters
pluginName: string
A plugin name.
Returns PluginData
getPluginEnabled
Returns the enabled state of a plugin.
Parameters
pluginName: string
Plugin name to set state.
Returns boolean
getPluginEventNames
Returns the event binding names registered on any associated plugin EventProxy.
Parameters
pluginName: string
Plugin name to set state.
Returns string[]
getPluginMethodNames
Returns all plugin names or if a boolean is passed in will return plugin names by current enabled state.
Parameters
enabled: boolean
If enabled is a boolean it will return plugins given their enabled state.
Returns { method: string; plugin: string }[]
getPluginNames
Returns all plugin names or if a boolean is passed in will return plugin names by current enabled state.
Parameters
enabled: boolean
If enabled is a boolean it will return plugins given their enabled state.
Returns string[]
getPluginOptions
Returns a copy of the given plugin options.
Parameters
pluginName: string
Plugin name to retrieve.
Returns any
getPluginsByEventName
Returns the plugin names that registered the given event binding name.
Parameters
eventName: string
An event name that plugins may have registered.
Returns string[]
getPluginsEnabled
Returns the enabled state of a list of plugins.
Parameters
pluginNames: string[]
An array / iterable of plugin names.
Returns { enabled: boolean; pluginName: string }[]
getPluginsEventNames
Returns the event binding names registered from each plugin.
Parameters
optionalnameOrList: string | string[]
An array / iterable of plugin names.
Returns { events: string[]; pluginName: string }[]
hasMethod
Returns true if there is at least one plugin loaded with the given method name.
Parameters
methodName: string
Method name to test.
Returns boolean
hasPlugin
Returns true if there is a plugin loaded with the given plugin name.
Parameters
pluginName: string
Plugin name to test.
Returns boolean
hasPluginMethod
Returns true if there is a plugin loaded with the given plugin name that also has a method with the given method name.
Parameters
pluginName: string
Plugin name to test.
methodName: string
Method name to test.
Returns boolean
invoke
This dispatch method simply invokes any plugin targets for the given methodName..
Parameters
methodName: string
Method name to invoke.
optionalargs: any
Optional arguments. An array will be spread as multiple arguments.
optionalnameOrList: string | string[]
An optional plugin name or array / iterable of plugin names to invoke.
Returns void
invokeAsync
This dispatch method uses ES6 Promises and adds any returned results to an array which is added to a Promise.all construction which passes back a Promise which waits until all Promises complete. Any target invoked may return a Promise or any result. This is very useful to use for any asynchronous operations.
Parameters
methodName: string
Method name to invoke.
optionalargs: any[]
Optional arguments. An array will be spread as multiple arguments.
optionalnameOrList: string | string[]
An optional plugin name or array / iterable of plugin names to invoke.
Returns Promise<any>
invokeAsyncEvent
This dispatch method synchronously passes to and returns from any invoked targets a PluginEvent.
Parameters
methodName: string
Method name to invoke.
optionalcopyProps: any
plugin event object.
optionalpassthruProps: any
if true, event has plugin option.
optionalnameOrList: string | string[]
An optional plugin name or array / iterable of plugin names to invoke.
Returns Promise<void | default>
invokeSync
This dispatch method synchronously passes back a single value or an array with all results returned by any invoked targets.
Parameters
methodName: string
Method name to invoke.
optionalargs: any
Optional arguments. An array will be spread as multiple arguments.
optionalnameOrList: string | string[]
An optional plugin name or array / iterable of plugin names to invoke.
Returns any
invokeSyncEvent
This dispatch method synchronously passes to and returns from any invoked targets a PluginEvent.
Parameters
methodName: string
Method name to invoke.
optionalcopyProps: any
plugin event object.
optionalpassthruProps: any
optionalnameOrList: string | string[]
An optional plugin name or array / iterable of plugin names to invoke.
Returns default
isValidConfig
Performs validation of a PluginConfig.
Parameters
pluginConfig: PluginConfig
A PluginConfig to validate.
Returns boolean
remove
Removes a plugin by name after unloading it and clearing any event bindings automatically.
Parameters
pluginName: string
The plugin name to remove.
Returns boolean
removeAll
Removes all plugins after unloading them and clearing any event bindings automatically.
Returns void
removeAllAsync
Removes all plugins after unloading them and clearing any event bindings automatically.
Returns Promise<any>
removeAsync
Removes a plugin by name after unloading it and clearing any event bindings automatically.
Parameters
pluginName: string
The plugin name to remove.
Returns Promise<boolean>
setEventbus
Sets the eventbus associated with this plugin manager. If any previous eventbus was associated all plugin manager events will be removed then added to the new eventbus. If there are any existing plugins being managed their events will be removed from the old eventbus and then
onPluginLoad
will be called with the new eventbus.Parameters
targetEventbus: EventEmitter
The target eventbus to associate.
optionaleventPrepend: string
An optional string to prepend to all of the event binding targets.
Returns default
setEventbusAsync
Sets the eventbus associated with this plugin manager. If any previous eventbus was associated all plugin manager events will be removed then added to the new eventbus. If there are any existing plugins being managed their events will be removed from the old eventbus and then
onPluginLoad
will be called with the new eventbus.Parameters
targetEventbus: EventEmitter
The target eventbus to associate.
optionaleventPrepend: string
An optional string to prepend to all of the event binding targets.
Returns Promise<default>
setExtraEventData
Sets any extra event data attached to PluginEvent
extra
field.Parameters
optionalextraEventData: any
Adds extra data to PluginEvent
extra
field.
Returns void
setOptions
Set optional parameters. All parameters are off by default.
Parameters
optionaloptions: PluginManagerOptions
Defines optional parameters to set.
Returns void
setPluginEnabled
Enables or disables a single plugin.
Parameters
pluginName: string
Plugin name to set state.
enabled: boolean
The new enabled state.
Returns boolean
setPluginsEnabled
Enables or disables a set of plugins given an array or iterabe of plugin names.
Parameters
pluginNames: string[]
An array / iterable of plugin names.
enabled: boolean
The new enabled state.
Returns boolean
default
Defines a class holding the data associated with a plugin including its instance.
constructor
Instantiates a PluginEntry.
Parameters
name: string
The plugin name.
data: any
Data describing the plugin, manager, and optional module data.
instance: any
The loaded plugin instance.
eventProxy: EventEmitter
An EventEmitter associated with the plugin wrapping the plugin manager eventbus.
Returns default
data
Get plugin data.
Returns any
enabled
Get enabled.
Returns boolean
Set enabled.
Parameters
enabled: boolean
New enabled state.
Returns void
eventProxy
Get associated EventProxy.
Returns EventEmitter
Parameters
eventProxy: EventEmitter
Returns void
instance
Get plugin instance.
Returns any
name
Get plugin name.
Returns string
staticescape
Provides a convenience method to escape file paths.
Parameters
value: string
A string to escape.
Returns string
default
Provides the data / event passed to all invoked methods in PluginManager#invokeSyncEvent. The
event.data
field is returned to the caller. Before returning though additional the following additional metadata
is attached:
(number) $$plugin_invoke_count
- The count of plugins invoked.
(Array
$$plugin_invoke_names
- The names of plugins invoked.constructor
Initializes PluginEvent.
Parameters
optionalcopyProps: {}
Event data to copy.
optionalpassthruProps: {}
Event data to pass through.
optionalextraEventData: any
Extra event data attached to
extra
.
Returns default
data
Provides the unified event data assigning any pass through data to the copied data supplied.
eventbus
The active EventProxy for that particular plugin.
extra
Stores any extra event data added to all PluginEvents.
ignoreKeys
list of keys to ignore
pluginName
The active plugin name.
pluginOptions
The active plugin options.
projectReport
TODO: i don’t know where this is set, but it is used in excomplex-project/plugins
settings
settings for the plugin instance
syntaxes
All loaded trait syntaxes for AST nodes
Type Aliases
PluginConfig
Type declaration
optionalinstance?: string
Defines an existing object instance to use as the plugin.
name: string
Defines the name of the plugin; if no
target
entry is present the name doubles as the target (please see target).optionaloptions?: any
Defines an object of options for the plugin.
optionaltarget?: string
Defines the target NPM module to load or defines a local file (full path or relative to current working directory to load.
PluginData
Type declaration
managerEventPrepend: string
The plugin manager event prepend string.
name: string
The name of the plugin.
option: any
Defines an object of options for the plugin.
scopedName: string
The name of the plugin with the plugin managers event prepend string.
target: string
Defines the target NPM module to loaded or defines a local file (full path or relative to current working directory to load.
targetEscaped: string
Provides the target, but properly escaped for RegExp usage.
type: string
The type of plugin:
instance
,require-module
, orrequire-path
.
PluginManagerOptions
Type declaration
noEventAdd: boolean
If true this prevents plugins from being added by
plugins:add
andplugins:add:all
events forcing direct method invocation for addition.noEventDestroy: boolean
If true this prevents the plugin manager from being destroyed by
plugins:destroy:manager
forcing direct method invocation for destruction.noEventOptions: boolean
If true this prevents setting options for the plugin manager by
plugins:destroy:manager
forcing direct method invocation for destruction.noEventRemoval: boolean
If true this prevents plugins from being removed by
plugins:remove
andplugins:remove:all
events forcing direct method invocation for removal.pluginsEnabled: boolean
If false all plugins are disabled.
throwNoMethod: boolean
If true then when a method fails to be invoked by any plugin an exception will be thrown.
throwNoPlugin: boolean
If true then when no plugin is matched to be invoked an exception will be thrown.
Scope
Type declaration
lineEnd: number
End line of method
lineStart: number
Start line of method
name: string
Name of the class or method
paramCount: number
(For method scopes) Number of parameters for method
type: string
Type of report to create
Provides a wrapper around PluginManager for ESComplexModule. Several convenience methods for the plugin callbacks properly manage and or create initial data that are processed by the plugins.
The default plugins loaded include: